@echo off

rem if you have a number in the namespace, then you get an error like this:
rem   - The type name:"schemas.opengis.net.kml.2_2_0" on the property:"Name" of type:"System.CodeDom.CodeNamespace" is not a valid language-independent type name. Parameter name: typeName

rem XSD does understand include, but not understand import
rem XSD can use multiple XSD files as parameters
rem the output filenames depend on the input filenames and the order of the input filenames

rem Does not work, as XSD does not support a direct URI:
rem xsd /namespace:schemas.opengis.net.kml.version_2_2_0 /classes http://docs.oasis-open.org/election/external/xAL.xsd

rem so you have to download first, then use relative directories; note you need to include all XSD files in the right dependent order:
echo xsd /namespace:schemas.opengis.net.kml.version_2_2_0 /classes docs.oasis-open.org/election/external/xAL.xsd schemas.opengis.net\kml\2.2.0\atom-author-link.xsd schemas.opengis.net\kml\2.2.0\ogckml22.xsd

rem we don't need xAL.cs any more: all types are inside ogckml22.cs because of the "import" of xAL.xsd in ogckml22.xsd (for using xAL:Address)
echo del xAL.cs

rem you get errors like this when deserializing using the above classes:
rem --- System.InvalidOperationException: 
rem Member PlacemarkType.Item of type schemas.opengis.net.kml.version_2_2_0.AbstractGeometryType 
rem hides base class member AbstractFeatureType.Item of type System.Object. 
rem Use XmlElementAttribute or XmlAttributeAttribute to specify a new name.

rem the problem is that .NET classes generated by XSD.EXE cannot cope with the nested nature of KML.
rem see http://groups.google.com/group/kml-support-advanced/browse_thread/thread/4b49aed948189be7/c8e57ae7dc988f67?lnk=gst&q=

rem XSDObjectGen or XSDClassGen
rem http://xsd2code.codeplex.com/

echo %~dp0
echo "C:\Program Files\Xsd2Code\Xsd2Code.exe" %~dp0schemas.opengis.net\kml\2.2.0\ogckml22.xsd bo.POI.KML /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- 
echo "C:\develop\codeplex\Xsd2Code-65925\Xsd2Code\Trunk\Xsd2Code.Console\bin\Debug\Xsd2Code.exe" %~dp0schemas.opengis.net\kml\2.2.0\ogckml22.xsd bo.POI.KML /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- 
echo "C:\develop\codeplex\Xsd2Code-65925\Xsd2Code\Trunk\Xsd2Code.Console\bin\Debug\Xsd2Code.exe" schemas.opengis.net\kml\2.2.0\ogckml22.xsd bo.POI.KML /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- /is+

echo "C:\develop\codeplex\Xsd2Code-65925\Xsd2Code\Trunk\Xsd2Code.Console\bin\Debug\Xsd2Code.exe" hexbinary.xsd bo.POI.KML.hexbinary /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- /is+
"C:\develop\codeplex\Xsd2Code-65925\Xsd2Code\Trunk\Xsd2Code.Console\bin\Debug\Xsd2Code.exe" %~dp0schemas.opengis.net\kml\2.2.0\atom-author-link.xsd bo.POI.KML.atom /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- /is+

rem C:\develop\codeplex\TFS05\bo\.NET\C#\bo.POI\schemas.opengis.net\kml\2.2.0\atom-author-link.xsd bo.POI.KML.atom /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- /is+
rem C:\develop\codeplex\TFS05\bo\.NET\C#\bo.POI\schemas.opengis.net\kml\2.2.0\ogckml22.xsd bo.POI.KML /platform Net35 /dc+ /cl+ /ap+ /sc+ /xa+ /hp- /is+

goto :end


C:\Program Files\Xsd2Code>Xsd2Code.exe

Xsd2Code Version 3.0.0.19191
Code generation utility from XML schema files.


Usage: Xsd2Code.exe <XSD File> <Namespace> [Options]

Where:
    <XSD File>                          - Path to an XSD file (Required)
    <Namespace>                         - Generated code namespace (Required)
    [Options]                           - Optional. See below for description

Options:

    /i[nput] <FileName>                 - Name of the input (XSD) file
    /o[utput] <FileName>                - Name of the output (generated) file.
                                          By default, name of the source file with extension .Designer.cs
                                          (.vb or .cpp for VisualVasic and Visual C++ respectively)
    /n[s] <Namespace>                   - Generated code CLR namespace. Default: file name without extension
    /l[anguage] <Language>              - Generated code language (CS|VB|CPP). Default: CS
    /pl[atform] <Platform>              - Generated code target platform (Net20|Net30|Net35|Silverlight20). Default: Net20
    /cb <Collection Base>               - Collection base (Array|List|ObservableCollection|DefinedType). Default: List
    /cu <Custom Usings>                 - Comma-separated of custom usings definition (E.g "Xsd2Code.Library,System.Xml.Linq")
    /sm <Serialize>                     - Serialize method name. Default: Serialize
    /dm <Deserialize>                   - Deserialize method name. Default: Deserialize
    /lf <LoadFromFile>                  - LoadFromFile method name. Default: LoadFromFile
    /sf <SaveToFile>                    - SaveToFile methodname. Default: SaveToFile
    /dbg[+]                             - Enable debug step through
    /dbg-                               - Disable debug step through (default)
    /db[+]                              - Enable data bindings
    /db-                                - Disable data bindings (default)
    /dc[+]                              - Generate WCF data contract attributes

    /dc-                                - Do not generate WCF data contract attributes (default)
    /cl[+]                              - Generate Clone method (shallow copy)
    /cl-                                - Do not generate Clone method (default)

    /ap[+]                              - Enable automatic properties
    /ap[-]                              - Disable automatic properties (default)

    /sc[+]                              - Enable summary comment
    /sc-                                - Disable summary comment (default)
    /xa[+]                              - Geneare xml attributes
    /xa[-]                              - Do not generate xml attributes (default)

    /hp[+]                              - Hide private fields in IDE
    /hp-                                - Show private fields in IDE (default)

    /?, /h[elp]                         - Show this help

Example:

        Xsd2Code.exe Employee.xsd CompanyXYZ.Entities.HumanResources /o Employee.cs /cb ObservableCollection /dbg



:end